package org.hzero.exam.api.controller.v1;

import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hzero.core.base.BaseController;
import org.hzero.core.util.Results;
import org.hzero.exam.api.dto.OrderItemDTO;
import org.hzero.exam.config.SwaggerTags;
import org.hzero.exam.domain.repository.OrderItemRepository;
import org.hzero.export.annotation.ExcelExport;
import org.hzero.export.vo.ExportParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author 马旭阳
 * @date2019/8/5
 * 操作数据导出接口的controller
 */
@Api(tags = SwaggerTags.EXPORT)
@RestController("exportController.v1")
@RequestMapping("/v1/{organizationId}/exports")
public class ExportController extends BaseController {
    @Autowired
    private OrderItemRepository orderItemRepository;

    /**
     * 订单明细数据导出
     * @param orderItem 订单明细数据所在的DTO类
     * @param exportParam 用于封装参数，必有
     * @param response 用于输出Excel,必有
     * @return org.springframework.http.ResponseEntity
     */
    @GetMapping("/export")
    @Permission(level = ResourceLevel.SITE)
    @ExcelExport(OrderItemDTO.class)
    @ApiOperation(value = "订单详细表excel导出")
    public ResponseEntity export(OrderItemDTO orderItem, ExportParam exportParam, HttpServletResponse response) {
        List<OrderItemDTO> list = orderItemRepository.exportOrder(orderItem,exportParam);
        return Results.success(list);
    }
}
